package com.bw.zg2.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.zg2.base.BaseResult
import com.bw.zg2.base.BaseViewModel
import com.bw.zg2.bean.BannerBean
import com.bw.zg2.bean.GoodsBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 *
 * @ClassName: HomeViewModel
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/14 11:49 AM
 * @Version: 1.0
 */
class HomeViewModel : BaseViewModel() {

    val bannerLiveData = MutableLiveData<BaseResult<List<BannerBean>>>()
    val homeListLiveData = MutableLiveData<BaseResult<GoodsBean>>()
    fun getBanner() {

        //开启协程，发送网络请求
        viewModelScope.launch(Dispatchers.IO) {
            bannerLiveData.postValue(apiService.getBanner())

        }

    }

    fun getHomeList(id: Int, page: Int, size: Int) {
        viewModelScope.launch(Dispatchers.IO) {
            homeListLiveData.postValue(apiService.getGoodsList(id, page, size))
        }
    }
}